
package com.ukao.cashregister.pesenter;

import android.content.Context;

import com.ukao.cashregister.base.BasePresenter;
import com.ukao.cashregister.bean.AccountLoginBean;
import com.ukao.cashregister.bean.TokenBean;
import com.ukao.cashregister.consts.Constant;
import com.ukao.cashregister.consts.SaveParamets;
import com.ukao.cashregister.retrofit.ApiCallback;
import com.ukao.cashregister.utils.CipherUtils;
import com.ukao.cashregister.utils.T;
import com.ukao.cashregister.view.AccountLoginView;

import java.util.HashMap;

/**
 * Created by ukaodev on 2017/6/28.
 */

public class AccountLoginPesenter extends BasePresenter<AccountLoginView> {
    private boolean isloaderr;

    public AccountLoginPesenter(AccountLoginView view) {
        attachView(view);
    }


    public void appSecretData(     ) {
        mvpView.showLoading();
        isloaderr=false;
        HashMap mHashMap = new HashMap<String, String>();
        addSubscription(apiStores.getToken(Constant.firstParameter(mHashMap)),
                new ApiCallback<TokenBean>() {
                    @Override
                    public void onSuccess(TokenBean model) {

                        if (model.getHttpCode() == 200) {

                            mvpView.appSecretSucceed(model);
                        }else{

                            mvpView.loadFailure(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();


                    }
                });
    }





    public void loginRequest(final   Context _mActivity,String  account ,String password ) {
       mvpView.showLoading();
        String  sign=SaveParamets.getsaveloginSign(_mActivity);
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("account", account);
        mHashMap.put("password", CipherUtils.md5(CipherUtils.md5(password)+sign));
        addSubscription(apiStores.login(Constant.createParameter(mHashMap)),
                new ApiCallback<AccountLoginBean>() {
                    @Override
                    public void onSuccess(AccountLoginBean model) {

                        if (model.getHttpCode()==200){
                            AccountLoginBean mitem = model.getData();
                            mvpView.loadloginSucceed(mitem);

                        }else{
                            T.show(model.getMsg());
                        }
                    }



                    @Override
                    public void onFinish() {


                        mvpView.hideLoading();

                    }
                });
    }


}
